package Gui;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
/**
 * this class implementes the book copy window 
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class TheBookIsCopy extends JFrame {
	
	private String[] str;

	
	public static String Copyname;
	
	
		
		public TheBookIsCopy(String[] str) {
				this.str=str;
			 initcomponent();	}
/**
 * init the book window 
 */
		public void initcomponent()
		{
		getContentPane().setBackground(new Color(153, 204, 255));
		

		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				AddBook.j=1;
			}
		});
		
		final JComboBox<String> comboBox = new JComboBox();
		for ( int i = 1 ; i <= this.str.length-1; i++)      // get the copy name 
			{comboBox.addItem(this.str[i]);
			}
		
		
		
		JButton btnConfirm = new JButton("Confirm");
		btnConfirm.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			
				AddBook.j=1;
				Copyname = (String) comboBox.getSelectedItem();
				dispose();
			}
		});
		
		JLabel lblCopy = new JLabel("This Book is Copy Of : ");
		lblCopy.setForeground(Color.BLUE);
		lblCopy.setFont(new Font("Tahoma", Font.BOLD, 24));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(111)
					.addComponent(btnCancel)
					.addGap(160)
					.addComponent(btnConfirm)
					.addGap(118))
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(52)
					.addComponent(comboBox, 0, 247, Short.MAX_VALUE)
					.addGap(55))
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(123)
					.addComponent(lblCopy)
					.addContainerGap(148, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addGap(24)
					.addComponent(lblCopy)
					.addGap(41)
					.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 144, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnCancel)
						.addComponent(btnConfirm))
					.addGap(32))
		);
		getContentPane().setLayout(groupLayout);
	}

		
}
